﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Web.UI;


namespace publico
{
    [Serializable]
    public class PUB_SESSAO 
    {
        #region Propriedades

        private static int _id;

        public static int Id
        {
            get
            {
                if (HttpContext.Current.Session["id"] == null)
                {
                    HttpContext.Current.Session["id"] = 0;
                }

                return _id = Convert.ToInt32(HttpContext.Current.Session["id"]);
            }
            set
            {
                HttpContext.Current.Session["id"] = Convert.ToInt32(value);
            }
        }

        private static string _id_session;

        public static string Id_session
        {
            get
            {
                if (HttpContext.Current.Session["id_session"] == null)
                {
                    HttpContext.Current.Session["id_session"] = 0;
                }
                return _id_session = HttpContext.Current.Session["id_session"].ToString();
            }
            set
            {
                HttpContext.Current.Session["id_session"] = value;
            }
        }


        private static string _login;

        public static string Login
        {
            get
            {
                if (HttpContext.Current.Session["login"] == null)
                {
                    HttpContext.Current.Session["login"] = string.Empty;
                }
                return _login = HttpContext.Current.Session["login"].ToString();

            }
            set
            {
                HttpContext.Current.Session["login"] = value;
            }
        }

        private static string _nome;

        public static string Nome
        {
            get
            {
                if (HttpContext.Current.Session["nome"] == null)
                {
                    HttpContext.Current.Session["nome"] = string.Empty;
                }
                return _nome = HttpContext.Current.Session["nome"].ToString();
            }
            set
            {
                HttpContext.Current.Session["nome"] = value;
            }
        }

        private static string _email;

        public static string Email
        {
            get
            {
                if (HttpContext.Current.Session["email"] == null)
                {
                    HttpContext.Current.Session["email"] = string.Empty;
                }
                return _email = HttpContext.Current.Session["email"].ToString();
            }
            set
            {
                HttpContext.Current.Session["email"] = value;
            }
        }

        private static int _id_empresa;

        public static int Id_empresa
        {
            get
            {
                if (HttpContext.Current.Session["id_empresa"] == null)
                {
                    HttpContext.Current.Session["id_empresa"] = string.Empty;
                }
                return _id_empresa = (int)HttpContext.Current.Session["id_empresa"];
            }
            set
            {
                HttpContext.Current.Session["id_empresa"] = value;
            }
        }
    

        private static int _id_perfil;

        public static int Id_perfil
        {
            get
            {
                if (HttpContext.Current.Session["id_perfil"] == null)
                {
                    HttpContext.Current.Session["id_perfil"] = 0;
                }
                return _id_perfil = (int)HttpContext.Current.Session["id_perfil"];
            }   
            set
            {
                HttpContext.Current.Session["id_perfil"] = value;
            }
        }

        private static bool _sit_ativo;

        public static bool Sit_ativo
        {
            get
            {
                if (HttpContext.Current.Session["sit_ativo"] == null)
                {
                    HttpContext.Current.Session["sit_ativo"] = false;
                }
                return _sit_ativo = (bool)HttpContext.Current.Session["sit_ativo"];
            }
            set
            {
                HttpContext.Current.Session["sit_ativo"] = value;
            }
        }

        private static int _tentativas;
        public static int Tentativas
        {
            get
            {
                if (HttpContext.Current.Session["tentativas"] == null)
                {
                    HttpContext.Current.Session["tentativas"] = 0;
                }
                return _tentativas = (int)HttpContext.Current.Session["tentativas"];
            }
            set
            {
                HttpContext.Current.Session["tentativas"] = value;
            }

        }

        private static bool _autenticado;

        public static bool Autenticado
        {
            get
            {
                if (HttpContext.Current.Session["autenticado"] == null)
                {
                    HttpContext.Current.Session["autenticado"] = false;
                }
                return _autenticado = (bool)HttpContext.Current.Session["autenticado"];
            }
            set
            {
                HttpContext.Current.Session["autenticado"] = value;
            }

        }

        public static bool Instalado
        {
            get
            {
                return (bool)HttpContext.Current.Session["instalado"];
            }
            set { HttpContext.Current.Session["instalado"] = value; }
        }


        public static Control Menu
        {
            get {                         
                return (Control)HttpContext.Current.Session["menu"]; }
            set { HttpContext.Current.Session["menu"] = value; }
        }
 
        public static bool Logado()
        {
            if (!PUB_SESSAO.Autenticado)
            {                
                HttpContext.Current.Response.Redirect("~/pagina/login/login_acesso.aspx", false);
                return false;
            }
            else
            {

                return true;
            }
        }

        public static void Logout()
        {

            if (HttpContext.Current.Cache["menu"] != null)
            {
                HttpContext.Current.Cache.Remove("menu");
            }

            HttpContext.Current.Session.Abandon();
            HttpContext.Current.Response.Redirect("~/pagina/login/login_acesso.aspx", false);

        }

        public static bool InclusaoEdicao
        {
            get
            {
                if (HttpContext.Current.Session["incluir_editar"] == null)
                {
                    HttpContext.Current.Session["incluir_editar"] = false;
                }
                return (bool)HttpContext.Current.Session["incluir_editar"];
            }
            set { HttpContext.Current.Session["incluir_editar"] = value; }
        }


        public static bool Navegacao
        {
            get
            {
                if (HttpContext.Current.Session["navegacao"] == null)
                {
                    HttpContext.Current.Session["navegacao"] = false;
                }
                return (bool)HttpContext.Current.Session["navegacao"];
            }
            set { HttpContext.Current.Session["navegacao"] = value; }
        }


        private static void ModoInclusaoEdicao()
        {

            PUB_SESSAO.InclusaoEdicao = true;
            PUB_SESSAO.Navegacao = false;

        }


        private static void ModoNavegacao()
        {
            PUB_SESSAO.InclusaoEdicao = false;
            PUB_SESSAO.Navegacao = true;
        }



        #endregion
    }
}
